<?php
/**
 * Created by PhpStorm .
 * User: {Administrator}
 * Date: {2022/7/27 16:18}
 * Author: '树叶'
 * Email: 'ayunu@qq.com'
 * Motto Info: '理想如果不向现实做一点点屈服，那么理想也将归于尘土。'
 */

namespace app\api\controller;
use app\api\model\GoodsShare;
use app\common\controller\Api;
use wxpay\Wechat;
use think\Db;
use app\api\model\Order as OrderModel;

class Payment extends Api
{
    public $noNeedLogin = ['*'];
    public $noNeedRight = ['*'];

    /**
     * 支付
     */
    public function pay()
    {
        $uid = $this->auth->id;
        $order_id = $this->request->post('order_id');  // 订单id
        $pay_way  = $this->request->post('pay_way',1);  // 支付方式 2余额,1微信
        $type  = $this->request->post('type','');       // 状态: goods 支付商品, money 充值余额

        if (!$type)    $this->success('请选择支付信息','',401);
        if (!$pay_way) $this->success('请选择支付方式','',401);

        if (!$uid) $this->success('请进行登录','',401);

        if (!$order_id) $this->success('请选择支付的订单','',400);

        $orderModel = new OrderModel();

        // 订单支付
        $res = $orderModel->Orderpay($uid, $order_id, $pay_way, $type);

        if ($res['status'])
        {
            if ($type == 'goods') { $share = GoodsShare::upShare($order_id); }

   
            $this->success('成功支付', $res, 200);
        }else{
            $this->success($res['msg'], '', 400);
        }
    }


    /**
     * 金币商品支付
     */
    public function Goldpay()
    {
        $uid = $this->auth->id;
        $order_id = $this->request->post('order_id');  // 订单id
        $type = $this->request->post('type',0);  //  添加
        if (!$uid) $this->success('请进行登录','',401);
        if (!$order_id) $this->success('请选择支付的订单','',4010);
        $orderModel = new OrderModel();
        $res = $orderModel->Orderglod($uid, $order_id);
        if ($res['status'])
        {
            $this->success($res['msg'], '', 200);
        }else{
            $this->success($res['msg'], '', 400);
        }
    }




}